package game.sloto;

import java.nio.CharBuffer;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;

public class FlashPolicyHandler extends IoHandlerAdapter {
	
	private final String POLICY_REQ = "<policy-file-request/>";
	private final String POLICY_RESP = "<cross-domain-policy>" +
			"<allow-access-from domain=\"*\" to-ports=\"*\" />" +
			"</cross-domain-policy>";
	
	@Override
	public void messageReceived(IoSession session, Object message)
			throws Exception {
		IoBuffer in = (IoBuffer) message;
		CharBuffer cb = in.asCharBuffer();
		if (cb.toString().equalsIgnoreCase(POLICY_REQ))
		{
			session.write(POLICY_RESP);
		}
		session.close(false);
	}
	
}
